/*!
    \copyright  Copyright (c) 2025 Qualcomm Technologies International, Ltd.
                All Rights Reserved.
                Qualcomm Technologies International, Ltd. Confidential and Proprietary.
    \version    
    \file
    \ingroup    mirror_profile
    \brief      Mirror profile le audio interfaces

*/

#include "mirror_profile_le_audio.h"

#ifdef ENABLE_LEA_CIS_DELEGATION

#include "mirror_profile_private.h"

static void mirrorProfile_PrintIsoHandles(kymera_le_audio_iso_handle_list_t *iso_handle_list)
{
    uint8 iso_index;

    MIRROR_LOG("mirrorProfile_PrintIsoHandles No of ISO handles %d", iso_handle_list->handle_count);

    for (iso_index = 0 ; iso_index <= iso_handle_list->handle_count ; iso_index++)
    {
        MIRROR_LOG("mirrorProfile_PrintIsoHandles Iso_handle[%d] = 0x%x, channels : 0x%x",
                    iso_index, iso_handle_list->handles[iso_index].handle, 
                    iso_handle_list->handles[iso_index].channels);
    }
}

void MirrorProfile_GetSinkIsoHandleInfo(kymera_le_audio_iso_handle_list_t *iso_handle_list)
{
    mirror_profile_lea_unicast_t *lea_unicast = MirrorProfile_GetLeaUnicastState();

    iso_handle_list->handles[0].handle = MirrorProfile_GetIsoHandleFromMirrorType(LE_AUDIO_ISO_DIRECTION_DL);
    iso_handle_list->handles[0].channels = lea_unicast->audio_config.sink_audio_channel_mask;
    iso_handle_list->handle_count++;

    if (MirrorProfile_GetIsoHandleOfRightAse() != LE_AUDIO_INVALID_ISO_HANDLE)
    {
        iso_handle_list->handles[1].handle = MirrorProfile_GetIsoHandleOfRightAse();
        iso_handle_list->handles[1].channels = lea_unicast->audio_config.sink_audio_channel_mask;
        iso_handle_list->handle_count++;
    }

    mirrorProfile_PrintIsoHandles(iso_handle_list);
}

bool MirrorProfile_IsLeAudioCisUplinkEnabledForSecondary(generic_source_t source)
{
    mirror_profile_lea_unicast_t *lea_unicast = MirrorProfile_GetLeaUnicastState();

    /* CIS direction Bit 0 for DL and Bit 1 for UL */
    unsigned cis_dir = MirrorProfile_IsPrimary() ? lea_unicast->peer_cis_dir
                                                 : lea_unicast->own_cis_dir;

    return lea_unicast->routed_source_type == source.type &&
           lea_unicast->routed_source == source.u.audio &&
           (cis_dir & LE_AUDIO_ISO_DIRECTION_UL);
}

#endif /* ENABLE_LEA_CIS_DELEGATION */
